package resource;

import java.io.*;

public class TryWithResourceDemo {

    public static void main(String[] args) {
        File srcFile = new File("d:" + File.separator + "html_logo.jpg");
        File dest = new File("d:" + File.separator + "dest.jpg");
        try (InputStream fin = new FileInputStream(srcFile); OutputStream fout = new FileOutputStream(dest);) {
            long startTime = System.currentTimeMillis();
            //一边读，一边写
            int data = -1;
            while ((data = fin.read()) != -1) {
                fout.write(data);
            }
            long endTime = System.currentTimeMillis();
            System.out.println("总用时：" + (endTime - startTime) + "毫秒");
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
